import 'dart:convert';
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:flutter_shop/utils/dio_http.dart';
import 'package:flutter_shop/widgets/page_content.dart';

class RegisterPage extends StatefulWidget {
  @override
  _RegisterPageState createState() => _RegisterPageState();
}

class _RegisterPageState extends State<RegisterPage> {
  final dio = Dio();
  Object info;

  void _registerHandler() async {
    var res = await DioUtils.postHttp('/index/config');
    var response = json.decode(res.toString());
    setState(() {
      info = response['msg'];
    });
    print(info);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('注册'),
      ),
      body: SafeArea(
        minimum: EdgeInsets.all(20),
        child: ListView(
          children: [
            TextField(
              decoration: InputDecoration(hintText: '请输入用户名', labelText: '用户名'),
            ),
            TextField(
              decoration: InputDecoration(hintText: '请输入密码', labelText: '密码'),
            ),
            TextField(
              decoration: InputDecoration(hintText: '确认密码', labelText: '确认密码'),
            ),
            Padding(padding: EdgeInsets.all(10)),
            ElevatedButton(
                onPressed: () => {_registerHandler()},
                child: Text('注册'),
                style: ButtonStyle(
                    backgroundColor: MaterialStateProperty.all(Colors.green))),
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                TextButton(
                    onPressed: () =>
                        {Navigator.pushReplacementNamed(context, 'login')},
                    child: Text(
                      '去登录',
                      style: TextStyle(color: Colors.green),
                    ))
              ],
            )
          ],
        ),
      ),
    );
  }
}
